package com.cskaoyan.controller.goods;

import com.cskaoyan.bean.bo.goodsbo.BasePageInfoQueryListBo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.po.MarketGoods;
import com.cskaoyan.bean.vo.goodsvo.CatAndBrandVO;
import com.cskaoyan.bean.bo.goodsbo.GoodsCreateBO;
import com.cskaoyan.bean.vo.goodsvo.QueryGoodsDetailsVo;
import com.cskaoyan.service.goods.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:todo 商品管理的controller
 * @Author:todo wang xv
 * @Date:todo 2022/11/19
 */
@RestController
@RequestMapping("admin/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    /**
     * @Description:todo 用于按页查询商品列表 GET
     * @Author:todo wang xv
     * @Date:todo 2022/11/19
     */
    @RequestMapping("list")
    public BaseRespVo queryGoodsList(BasePageInfoQueryListBo basePageInfo) {
        CommonData<MarketGoods> data = goodsService.queryGoodsList(basePageInfo);
        return BaseRespVo.succeed(data);
    }

    /**
     * @Description:todo 用于显示商品增加的规格厂商之类的信息 GET
     * @Author:todo wang xv
     * @Date:todo 2022/11/19
     */
    @RequestMapping("catAndBrand")
    public BaseRespVo queryCatAndBrand() {
        CatAndBrandVO catAndBrandVO = goodsService.queryCatAndBrandList();
        return BaseRespVo.succeed(catAndBrandVO);
    }

    /**
     * @Description:todo 用于商品的添加 POST
     * @Author:todo wang xv
     * @Date:todo 2022/11/20
     */
    @RequestMapping("create")
    public BaseRespVo goodsCreate(@RequestBody GoodsCreateBO goodsCreateBO) {
        goodsService.insertGoods(goodsCreateBO);
        return BaseRespVo.succeed();
    }

    /**
     * @Description:todo 商品的删除
     * @Author:todo wang xv
     * @Date:todo 2022/11/20
     */
    @RequestMapping("delete")
    public BaseRespVo goodsDelete(@RequestBody MarketGoods goods) {
        goodsService.deleteGoods(goods);
        return BaseRespVo.succeed();
    }

    /**
    * @Description:todo 编辑商品时回显 GET
    * @Author:todo wang xv
    * @Date:todo 2022/11/21
    */
    @RequestMapping("detail")
    public BaseRespVo goodsDetail(Integer id){
       QueryGoodsDetailsVo goodsDetailsVo = goodsService.queryGoodsDetailById(id);
       return BaseRespVo.succeed(goodsDetailsVo);
    }

    /**
    * @Description:todo 编辑商品
    * @Author:todo wang xv
    * @Date:todo 2022/11/21
    */
    @RequestMapping("update")
    public BaseRespVo goodsUpdate(@RequestBody GoodsCreateBO goodsCreateBO){
        goodsService.updateGoods(goodsCreateBO);
        return BaseRespVo.succeed();
    }

}
